/**
 * 文  件  名：  ShuoShuoDaoProxy.java
 * 工  程  名：  7You
 * 创建日期：  2013-10-14
 * 创建作者：  杨  强
 */
package com.qiyou.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.qiyou.dao.IShuoShuoDao;
import com.qiyou.dao.impl.ShuoShuoDaoImpl;
import com.qiyou.db.IDatabase;
import com.qiyou.entity.ShuoShuo;
import com.qiyou.util.DBUtil;

/**
 * @author 杨 强
 * 
 */
public class ShuoShuoDaoProxy implements IShuoShuoDao {
    private Connection conn = null;
    private IShuoShuoDao dao = null;

    public ShuoShuoDaoProxy(IDatabase database) {
        this.conn = database.getConnection();
        this.dao = new ShuoShuoDaoImpl(conn);
    }

    @Override
    public boolean doCreate(ShuoShuo shuoShuo) throws SQLException {
        boolean result = false;
        if (null != shuoShuo) {
            try {
                result = dao.doCreate(shuoShuo);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doUpdate(ShuoShuo shuoShuo) throws SQLException {
        boolean result = false;
        if (null != shuoShuo) {
            try {
                result = dao.doUpdate(shuoShuo);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doDelete(long shuoShuoID) throws SQLException {
        boolean result = false;
        try {
            result = dao.doDelete(shuoShuoID);
        } catch (SQLException e) {
            throw e;
        } finally {
            DBUtil.closeConnection(conn);
        }
        return result;
    }

    @Override
    public ShuoShuo getShuoShuo(long shuoShuoID) throws SQLException {
        ShuoShuo result = null;
        try {
            result = dao.getShuoShuo(shuoShuoID);
        } catch (SQLException e) {
            throw e;
        } finally {
            DBUtil.closeConnection(conn);
        }
        return result;
    }

    @Override
    public List<ShuoShuo> getShuoShuos(String userID) throws SQLException {
        List<ShuoShuo> result = null;
        if ((null != userID) && (!userID.isEmpty())) {
            try {
                result = dao.getShuoShuos(userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return result;
    }

    @Override
    public List<ShuoShuo> getShuoShuos(Object... params) throws SQLException {
        List<ShuoShuo> result = null;
        if (null != params) {
            try {
                result = dao.getShuoShuos(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                DBUtil.closeConnection(conn);
            }
        }
        return result;
    }

}
